package com.dushibao.utils;

public class StringUtils {

    public static void main(String[] args) {
        String name = "parent_id";
        System.out.println(columnNameToJavaName(name));
    }

    public static String columnNameToJavaName(String name){

        if(name.contains("_")){
            String[] names = name.split("_");
            String ret  = names[0];
            for(int i=1;i<names.length;i++){
                String v = names[i];
                v = v.toLowerCase();
                v = v.substring(0,1).toUpperCase() + v.substring(1);
                ret += v;
            }
            return ret;
        }

        return name;
    }



    public static String getName(String name){
        return getName(name,name).replace("_","");
    }

    private static String getName(String name,String  anotherName) {
        name=anotherName;
        //如果最后一个是_ 不做转换
        if(name.indexOf("_")>0&&name.length()!=name.indexOf("_")+1){
            int lengthPlace=name.indexOf("_");
            name=name.replaceFirst("_", "");
            String s=name.substring(lengthPlace, lengthPlace+1);
            s=s.toUpperCase();
            anotherName=name.substring(0,lengthPlace)+s+name.substring(lengthPlace+1);
        }else{
            return  anotherName;
        }
        return getName(name,anotherName);
    }
}